home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / mach / sun4c.md / mach.h < prev    next >
C/C++ Source or Header  |  1991-07-26  |  7KB  |  245 lines

  1. /*
  2.  * mach.h --
  3.  *
  4.  *     Exported structures for the mach module.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  * $Header: /sprite/src/kernel/mach/sun4.md/RCS/mach.h,v 9.10 91/07/26 17:04:30 shirriff Exp $ SPRITE (Berkeley)
  16.  */
  17.  
  18. #ifndef _MACH
  19. #define _MACH
  20.  
  21. #ifdef KERNEL
  22. #include "machTypes.h"
  23. #include <user/setjmp.h>
  24. #else
  25. #include <kernel/machTypes.h>
  26. #include <setjmp.h>
  27. #endif
  28.  
  29. #ifdef lint
  30. #define    Mach_EnableIntr()
  31. #define    Mach_DisableIntr()
  32. #else
  33. /*
  34.  * Routines to enable and disable interrupts.  These leave unmaskable
  35.  * interrupts enabled.  These are assembly macros to be called from C code.
  36.  * They use the in-line capabilities of GCC.
  37.  */
  38. #define    Mach_EnableIntr()    {\
  39.     register unsigned int    tmpPsr;    \
  40.     asm volatile ( "mov    %%psr, %0;    \
  41.             andn    %0, 0xf00, %0;    \
  42.             mov    %0, %%psr; nop; nop; nop\n":    \
  43.             "=r"(tmpPsr));    \
  44.     }
  45.  
  46. #define    Mach_DisableIntr()    {\
  47.     register unsigned int tmpPsr;    \
  48.     asm volatile ( "mov    %%psr, %0;    \
  49.             or    %0, 0xf00, %0;    \
  50.             mov    %0, %%psr; nop; nop; nop\n":    \
  51.             "=r"(tmpPsr));    \
  52.     }
  53. #endif /* lint */
  54.  
  55.  
  56. #define DISABLE_INTR() \
  57.     if (!Mach_AtInterruptLevel()) { \
  58.     Mach_DisableIntr(); \
  59.     if (mach_NumDisableIntrsPtr[0] < 0) { \
  60.         panic("Negative interrupt count.\n"); \
  61.     } \
  62.     mach_NumDisableIntrsPtr[0]++; \
  63.     }
  64. #define ENABLE_INTR() \
  65.     if (!Mach_AtInterruptLevel()) { \
  66.     mach_NumDisableIntrsPtr[0]--; \
  67.     if (mach_NumDisableIntrsPtr[0] < 0) { \
  68.         panic("Negative interrupt count.\n"); \
  69.     } \
  70.     if (mach_NumDisableIntrsPtr[0] == 0) { \
  71.         Mach_EnableIntr(); \
  72.     } \
  73.     }
  74.  
  75. /*
  76.  * A macro to test if the current processor is at interrupt level.
  77.  */
  78.  
  79. #define    Mach_AtInterruptLevel()    (mach_AtInterruptLevel)
  80.  
  81. /*
  82.  * A macro to test if the current processor is in kernel mode.
  83.  */
  84.  
  85. #define    Mach_KernelMode() (mach_KernelMode)
  86.  
  87. /*
  88.  * A macro to return the current interrupt nesting level.
  89.  */
  90.  
  91. #define    Mach_IntrNesting(cpu)    (mach_NumDisableIntrsPtr[(cpu)])
  92.  
  93. /*
  94.  * Delay for N microseconds.
  95.  */
  96. #define    MACH_DELAY(n)    { register int N = (n)<<3; N--; while (N > 0) {N--;} }
  97.  
  98. /*
  99.  * The interrupt register on a sun4.
  100.  */
  101. #define    Mach_InterruptReg    ((unsigned char *) DEV_INTERRUPT_REG_ADDR)
  102.  
  103. /*
  104.  * Suns don't have a write buffer, but this macro makes it easier to
  105.  * write machine-independent device drivers for both the Decstations and Suns.
  106.  */
  107. #define Mach_EmptyWriteBuffer()
  108.  
  109. #define Mach_SetErrno(err) Proc_GetActualProc()->unixErrno = (err)
  110.  
  111. /*
  112.  * Dispatch tables for kernel calls.
  113.  */
  114. extern ReturnStatus (*(mach_NormalHandlers[]))();
  115. extern ReturnStatus (*(mach_MigratedHandlers[]))();
  116.  
  117. /*
  118.  * Macro to get processor number
  119.  */
  120. #define    Mach_GetProcessorNumber()     0
  121.  
  122. /*
  123.  * Macro to get the user's stack pointer.
  124.  */
  125. #define Mach_UserStack() ((Address)machCurStatePtr->trapRegs->ins[6])
  126.  
  127. extern    Address    Mach_GetPC _ARGS_((void));
  128. extern    Address    Mach_GetCallerPC _ARGS_((void));
  129.  
  130. extern    Boolean    mach_KernelMode;
  131. extern    int    mach_NumProcessors;
  132. extern    Boolean    mach_AtInterruptLevel;
  133. extern    int    *mach_NumDisableIntrsPtr;
  134. /*
  135.  * mach_MachineType is a string used to expand $MACHINE in pathnames.
  136.  */
  137. extern    char    *mach_MachineType;
  138. /*
  139.  * mach_Format defines a byte ordering/structure alignment type
  140.  * used when servicing IOControls.  The input and output buffers for
  141.  * IOControls have to be made right by the server.
  142.  */
  143. extern    Fmt_Format    mach_Format;
  144.  
  145. /*
  146.  * Routine to initialize mach module.  Must be called first as part of boot
  147.  * sequence.
  148.  */
  149. extern void    Mach_Init _ARGS_((void));
  150.  
  151. /*
  152.  * Macro to put some primitive debugging values into a circular buffer.
  153.  * After each value, it stamps a special mark, which gets overwritten by the
  154.  * next value, so we always know where the end of the list is.
  155.  */
  156. extern    int    debugCounter;
  157. extern    int    debugSpace[];
  158. #define    MACH_DEBUG_ADD(thing)    \
  159.     debugSpace[debugCounter++] = (int)(thing);    \
  160.     if (debugCounter >= 500) {    \
  161.     debugCounter = 0;    \
  162.     }                \
  163.     debugSpace[debugCounter] = (int)(0x11100111);
  164.  
  165. /*
  166.  * Routines to munge machine state struct.
  167.  */
  168. #ifdef KERNEL
  169. #include "procMigrate.h"
  170. #else
  171. #include <kernel/procMigrate.h>
  172. #endif
  173.  
  174. extern void Mach_InitFirstProc _ARGS_((Proc_ControlBlock *procPtr));
  175. extern ReturnStatus Mach_SetupNewState _ARGS_((Proc_ControlBlock *procPtr, Mach_State *fromStatePtr, void (*startFunc)(), Address startPC, Boolean user));
  176. extern void Mach_SetReturnVal _ARGS_((Proc_ControlBlock *procPtr, int retVal,
  177.     int retVal2));
  178. extern void Mach_StartUserProc _ARGS_((Proc_ControlBlock *procPtr, Address entryPoint));
  179. extern void Mach_ExecUserProc _ARGS_((Proc_ControlBlock *procPtr, Address userStackPtr, Address entryPoint));
  180. extern void Mach_FreeState _ARGS_((Proc_ControlBlock *procPtr));
  181. extern void Mach_GetDebugState _ARGS_((Proc_ControlBlock *procPtr, Proc_DebugState *debugStatePtr));
  182. extern void Mach_SetDebugState _ARGS_((Proc_ControlBlock *procPtr, Proc_DebugState *debugStatePtr));
  183.  
  184. /*
  185.  * Migration routines.
  186.  */
  187. extern ReturnStatus Mach_EncapState _ARGS_((register Proc_ControlBlock *procPtr, int hostID, Proc_EncapInfo *infoPtr, Address buffer));
  188. extern ReturnStatus Mach_DeencapState _ARGS_((register Proc_ControlBlock *procPtr, Proc_EncapInfo *infoPtr, Address buffer));
  189. extern ReturnStatus Mach_GetEncapSize _ARGS_((Proc_ControlBlock *procPtr, int hostID, Proc_EncapInfo *infoPtr));
  190. extern Boolean Mach_CanMigrate _ARGS_((Proc_ControlBlock *procPtr));
  191. extern int Mach_GetLastSyscall _ARGS_((void));
  192.  
  193.  
  194. extern void Mach_SetHandler _ARGS_((int vectorNumber, int (*handler)(), ClientData clientData));
  195.  
  196. extern void Mach_InitSyscall _ARGS_((int callNum, int numArgs, ReturnStatus (*normalHandler)(), ReturnStatus (*migratedHandler)()));
  197.  
  198. extern ReturnStatus    Mach_Probe _ARGS_((int byteCount, Address readAddress, Address writeAddress));
  199.  
  200. /*
  201.  * Other routines.
  202.  */
  203. extern Mach_ProcessorStates Mach_ProcessorState _ARGS_((int processor));
  204. extern int Mach_GetNumProcessors _ARGS_((void));
  205. extern int Mach_GetBootArgs _ARGS_((int argc, int bufferSize, char **argv, char *buffer));
  206.  
  207.  
  208. /*
  209.  * Machine dependent routines.
  210.  */
  211. extern    Net_EtherAddress    *Mach_GetEtherAddress _ARGS_((Net_EtherAddress *etherAddress));
  212. extern    void    Mach_ContextSwitch _ARGS_((Proc_ControlBlock *fromProcPtr, Proc_ControlBlock *toProcPtr));
  213. extern    int    Mach_TestAndSet _ARGS_((int *intPtr));
  214. extern    int    Mach_GetMachineType _ARGS_((void));
  215. extern int Mach_GetMachineArch _ARGS_((void));
  216. extern void Mach_FlushWindowsToStack _ARGS_((void));
  217. extern    Address    Mach_GetStackPointer _ARGS_((void));
  218. extern void Mach_CheckSpecialHandling _ARGS_((int pnum));
  219. extern void Mach_Return2 _ARGS_((int val));
  220. extern int Mach_SigreturnStub _ARGS_((jmp_buf *jmpBuf));
  221.  
  222.  
  223. /*
  224.  * spriteStart is defined in bootSys.s with an underscore.
  225.  */
  226. extern    int        spriteStart;
  227. extern    int        endBss;
  228. extern    int        endText;
  229.  
  230. /*
  231.  * Machine dependent variables.
  232.  */
  233. extern    Address    mach_KernStart;
  234. extern    Address    mach_CodeStart;
  235. extern    Address    mach_StackBottom;
  236. extern    int    mach_KernStackSize;
  237. extern    Address    mach_KernEnd;
  238. extern    Address    mach_FirstUserAddr;
  239. extern    Address    mach_LastUserAddr;
  240. extern    Address    mach_MaxUserStackAddr;
  241. extern    int    mach_LastUserStackPage;
  242. extern    Mach_State  *machCurStatePtr;
  243.  
  244. #endif /* _MACH */
  245.